package com.yiyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yiyi.common.annotation.Log;
import com.yiyi.common.core.controller.BaseController;
import com.yiyi.common.core.domain.AjaxResult;
import com.yiyi.common.enums.BusinessType;
import com.yiyi.system.domain.CsDomainConfig;
import com.yiyi.system.service.ICsDomainConfigService;
import com.yiyi.common.utils.poi.ExcelUtil;
import com.yiyi.common.core.page.TableDataInfo;

/**
 * 开户域名管理Controller
 *
 * @author yiyi
 * @date 2024-10-12
 */
@RestController
@RequestMapping("/system/domainConfig")
public class CsDomainConfigController extends BaseController
{
    @Autowired
    private ICsDomainConfigService csDomainConfigService;

    /**
     * 查询开户域名管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:domainConfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(CsDomainConfig csDomainConfig)
    {
        startPage();
        List<CsDomainConfig> list = csDomainConfigService.selectCsDomainConfigList(csDomainConfig);
        return getDataTable(list);
    }

    /**
     * 查询全部开户域名列表
     * @param csDomainConfig
     * @return
     */
    @GetMapping("/listAll")
    public AjaxResult listAll(CsDomainConfig csDomainConfig)
    {
        List<CsDomainConfig> list = csDomainConfigService.selectCsDomainConfigList(csDomainConfig);
        return success(list);
    }

    /**
     * 根据域名获取信息
     * @param csDomainConfig
     * @return
     */
    @GetMapping("getDomainDataByDomain")
    public AjaxResult getDomainDataByDomain(CsDomainConfig csDomainConfig)
    {
        CsDomainConfig domainDataByDomain = csDomainConfigService.getDomainDataByDomain(csDomainConfig);
        return success(domainDataByDomain);
    }

    /**
     * 导出开户域名管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:domainConfig:export')")
    @Log(title = "开户域名管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CsDomainConfig csDomainConfig)
    {
        List<CsDomainConfig> list = csDomainConfigService.selectCsDomainConfigList(csDomainConfig);
        ExcelUtil<CsDomainConfig> util = new ExcelUtil<CsDomainConfig>(CsDomainConfig.class);
        util.exportExcel(response, list, "开户域名管理数据");
    }

    /**
     * 获取开户域名管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:domainConfig:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(csDomainConfigService.selectCsDomainConfigById(id));
    }

    /**
     * 新增开户域名管理
     */
    @PreAuthorize("@ss.hasPermi('system:domainConfig:add')")
    @Log(title = "开户域名管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CsDomainConfig csDomainConfig)
    {
        return toAjax(csDomainConfigService.insertCsDomainConfig(csDomainConfig));
    }

    /**
     * 修改开户域名管理
     */
    @PreAuthorize("@ss.hasPermi('system:domainConfig:edit')")
    @Log(title = "开户域名管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CsDomainConfig csDomainConfig)
    {
        return toAjax(csDomainConfigService.updateCsDomainConfig(csDomainConfig));
    }

    /**
     * 删除开户域名管理
     */
    @PreAuthorize("@ss.hasPermi('system:domainConfig:remove')")
    @Log(title = "开户域名管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(csDomainConfigService.deleteCsDomainConfigByIds(ids));
    }
}
